<?php
/*
 * Page management
 */
class Admin_SiteController extends H_Controller_Admin_Action
{
    const CURRENT_SITE = 1;

    public function init()
    {
        parent::init(); 
        $this->view->headTitle('CMS | Site');
    }
    
    public function indexAction(){
        $this->_redirect(BASE_URL."admin/site/config");
    }
    public function configAction(){
        $site = new H_Model_Site(self::CURRENT_SITE);
        if ($this->_request->isPost()){
            $data = $this->_getAllParams();
            $site->updateMeta(H_Model_Site::DEFAULT_LANG, $data['default_lang']);
            $site->updateMeta(H_Model_Site::PAGE_CACHE_TIME, $data['page_cache_time']);
            $site->updateMeta(H_Model_Site::SITE_OFF_MESSAGE, $data['site_off_message']);            
            $site->updateMeta(H_Model_Site::SMTP_FROM_MAIL, $data['smtp_from_mail']);
            $site->updateMeta(H_Model_Site::SMTP_FROM_NAME, $data['smtp_from_name']);
            $site->updateMeta(H_Model_Site::SMTP_HOST, $data['smtp_host']);
            $site->updateMeta(H_Model_Site::SMTP_PORT, $data['smtp_port']);
            $site->updateMeta(H_Model_Site::SMTP_ENCRY, $data['smtp_encryption']);
            $site->updateMeta(H_Model_Site::SMTP_USER, $data['smtp_user']);
            $site->updateMeta(H_Model_Site::SMTP_PASS, $data['smtp_pass']); 
            $where['id = ?'] = self::CURRENT_SITE;            
            $site->update(array(
                'sitename'=>$data['sitename'],
                'status' => $data['status']=='Yes'?1:0
                ), $where);
            $this->view->updateMes = true;
        }
        $siteInfo = $site->find(self::CURRENT_SITE)->toArray();        
        $this->view->siteInfo = $siteInfo[0];
        $this->view->siteMeta = $site->getAllMeta();
    }
    public function putAction() {
    }
    public function postAction() {
    }
    public function  getAction() {
    }
    public function  deleteAction() {
    }
    public function  postDispatch() {
        parent::postDispatch();        
    }
    public function listAction(){                
    }
    //Action nay chi dung de test lam template tra cuu cho nhung cai khac   
}


